class Solution {
public:
    void Adjsutdown(vector<int>& a, int n, int parent)
    {
        int child = parent * 2 + 1;
        while (child < n) {
            if (child + 1 < n && a[child] < a[child + 1])
            {
                child++;
            }
            if (a[child] > a[parent])
            {
                swap(a[child], a[parent]);
                parent = child;
                child = parent * 2 + 1;
            }
            else
            {
                break;
            }
        }
    }

    void HeapSort(vector<int>& a, int n)
    {
        for (int i = (n - 2) / 2; i >= 0; i--)
        {
            Adjsutdown(a, n, i);
        }
        int end = n - 1;
        while (end > 0)
        {
            swap(a[0], a[end]);
            Adjsutdown(a, end, 0);
            end--;
        }
    }

    vector<int> GetLeastNumbers_Solution(vector<int>& input, int k)
    {
        int n = input.size();
        if (k == 0 || n == 0)
        {
            return vector<int>();
        }
        HeapSort(input, n);
        vector<int> output(k);
        for (int i = 0; i < k; i++)
        {
            output[i] = input[i];
        }
        return output;
    }
};